<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Free Variables Tests</title>
<script src="../../src/util/sets.js"></script>
<script src="../../src/util/freevars.js"></script>
<script src="../../site/esparser/bundle.js"></script>
</head>

<body>

<style>
.running { background-color: yellow }
.pass { background-color: #afa }
.fail { background-color: #faa }
td { font-family: monospace }
</style>

<table id=tests>
  <tr><th>Code<th>Let Scope Decls<th>Var Scope Decls<th>Required Names
    <th>Free Names<th>Free Labels</tr>
  <tr><td>0<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>x<td>[]<td>[]<td>[x]<td>[x]<td>[]</tr>
  <tr><td>var x;<td>[]<td>[x]<td>[]<td>[x]<td>[]</tr>
  <tr><td>var x, y = z;<td>[]<td>[x, y]<td>[z]<td>[x, y, z]<td>[]</tr>
  <tr><td>x(); { var x; }<td>[]<td>[x]<td>[x]<td>[x]<td>[]</tr>
  <tr><td>function f(a) { var b; return a + b; }<td>[f]<td>[]<td>[]<td>[f]<td>[]</tr>
  <tr><td>(function f(a) { var b; return a + b; })<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>function f(a) { function g(b) { return a + b + c; }; return g; }</td>
      <td>[f]<td>[]<td>[c]<td>[c, f]<td>[]</tr>
  <tr><td>for (var i = 0, o; o = arr[i]; ++i) { foo(o); }</td>
      <td>[]<td>[i, o]<td>[arr, foo, i, o]<td>[arr, foo, i, o]<td>[]</tr>
  <tr><td>(function (arr) { for (var i = 0, o; o = arr[i]; ++i) { foo(o); } })()</td>
      <td>[]<td>[]<td>[arr, foo]<td>[arr, foo]<td>[]</tr>
  <tr><td>(function a(b, c) { var d; function e(f) { var g; } return [a,b,c,d,e,f,g,h]; })</td>
      <td>[]<td>[]<td>[f, g, h]<td>[f, g, h]<td>[]</tr>
  <tr><td>var a = function a(b, c) {}, d = e;</td>
      <td>[]<td>[a, d]<td>[e]<td>[a, d, e]<td>[]</tr>
  <tr><td>for (var k in o) { foo(o[k]); }</td>
      <td>[]<td>[k]<td>[foo, k, o]<td>[foo, k, o]<td>[]</tr>
  <tr><td>for (k in o) { foo(o[k]); }</td>
      <td>[]<td>[]<td>[foo, k, o]<td>[foo, k, o]<td>[]</tr>
  <tr><td>try { f(e); } catch (e) { g(e); }</td>
      <td>[]<td>[]<td>[e, f, g]<td>[e, f, g]<td>[]</tr>
  <tr><td>try { f(h); } catch (e) { g(e); }</td>
      <td>[]<td>[]<td>[f, g, h]<td>[f, g, h]<td>[]</tr>
  <tr><td>try { f(h); } catch (e) { g(e); } finally { g(e); }</td>
      <td>[]<td>[]<td>[e, f, g, h]<td>[e, f, g, h]<td>[]</tr>
  <tr><td>try { f(h); } catch (e) { var x = g(e); }</td>
      <td>[]<td>[x]<td>[f, g, h]<td>[f, g, h, x]<td>[]</tr>
  <tr><td>try { f(h); } catch (e) { var e = g(e); }</td>
      <td>[]<td>[e]<td>[f, g, h]<td>[e, f, g, h]<td>[]</tr>
  <tr><td>try { f(h); } catch (e) { g(e); } finally { var e = g(e); }</td>
      <td>[]<td>[e]<td>[f, g, h]<td>[e, f, g, h]<td>[]</tr>
  <tr><td>(function () { return [this, that, arguments, argumentative, null, undefined]; })</td>
      <td>[]<td>[]<td>[argumentative, that, undefined]</td>
      <td>[argumentative, that, undefined]<td>[]</tr>
  <tr><td>[this, that, arguments, argumentative, null, undefined]</td>
      <td>[]<td>[]<td>[argumentative, arguments, that, this, undefined]</td>
      <td>[argumentative, arguments, that, this, undefined]<td>[]</tr>
  <tr><td>foo: break;<td>[]<td>[]<td>[]<td>[]<td>[default]</tr>
  <tr><td>foo: continue;<td>[]<td>[]<td>[]<td>[]<td>[continue default]</tr>
  <tr><td>foo: break bar;<td>[]<td>[]<td>[]<td>[]<td>[bar]</tr>
  <tr><td>foo: continue bar;<td>[]<td>[]<td>[]<td>[]<td>[continue bar]</tr>
  <tr><td>bar: break bar;<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: continue bar;<td>[]<td>[]<td>[]<td>[]<td>[continue bar]</tr>
  <tr><td>bar: while (1) { break bar; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: while (1) { continue bar; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: while (1) { break; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: while (1) { continue; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: do { break bar; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: do { continue bar; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: do { break; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: do { continue; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: for (;;) { break bar; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: for (;;) { continue bar; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: for (;;) { break; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: for (;;) { continue; }<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>bar: switch (x) { default: break bar; }<td>[]<td>[]<td>[x]<td>[x]<td>[]</tr>
  <tr><td>bar: switch (x) { default: continue bar; }<td>[]<td>[]<td>[x]<td>[x]<td>[continue bar]</tr>
  <tr><td>bar: switch (x) { default: break; }<td>[]<td>[]<td>[x]<td>[x]<td>[]</tr>
  <tr><td>bar: switch (x) { default: continue; }<td>[]<td>[]<td>[x]<td>[x]<td>[continue default]</tr>
  <tr><td>do { break; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>do { continue; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>do { break bar; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[bar]</tr>
  <tr><td>do { continue bar; } while (1)<td>[]<td>[]<td>[]<td>[]<td>[continue bar]</tr>
  <tr><td>return<td>[]<td>[]<td>[]<td>[]<td>[return]</tr>
  <tr><td>return bar<td>[]<td>[]<td>[bar]<td>[bar]<td>[return]</tr>
  <tr><td>(function () { return })()<td>[]<td>[]<td>[]<td>[]<td>[]</tr>
  <tr><td>(function () { return bar })()<td>[]<td>[]<td>[bar]<td>[bar]<td>[]</tr>
  <tr><td>eval('alert("foo")')<td>[]<td>[]<td>[eval]<td>[eval]<td>[]</tr>
  <tr><td>eval('alert("foo")', bar)<td>[]<td>[]<td>[bar, eval]<td>[bar, eval]<td>[]</tr>
</table>

<script>(function () {
  if (!Date.now) { Date.now = function () { return +(new Date); }; }

  var testsCont = document.getElementById('tests');
  var tests = testsCont.getElementsByTagName('tr');
  var group = function () {};
  var groupEnd = function () {};
  var log = function () {};
  if (typeof console !== 'undefined' && console.group) {
    group = function (name) { console.group(name); };
    groupEnd = function () { console.groupEnd(); };
    log = function (var_args) { console.log.apply(console, arguments); };
  }
  function innerText(el) {
    return el.innerText || el.firstChild.nodeValue;
  }
  function check(cell, actual) {
    actual = '' + actual;
    var expected = innerText(cell);
    if (actual === expected) {
      cell.className = 'pass';
      return true;
    } else {
      cell.className = 'fail';
      cell.appendChild(document.createTextNode(' ; was ' + actual));
      return false;
    }
  }
  var i = 1 /* skip header */, n = tests.length;
  function doTest() {
    if (i == n) { return; }
    setTimeout(doTest, 100);
    var test = tests[i++];

    test.className = 'running';
    var cells = test.getElementsByTagName('td');
    var code = innerText(cells[0]);
    group(code);
    try {
      var t0 = Date.now();
      var ast = ES5Parser.matchAll(code, 'Program', [], function () {});
      var t1 = Date.now();
      var passed = true;
      if (ast) {
        passed &= check(cells[1], let_scoped_decls(ast));
        passed &= check(cells[2], var_scoped_decls(ast));
        passed &= check(cells[3], required_names(ast));
        passed &= check(cells[4], free_names(ast));
        passed &= check(cells[5], free_labels(ast));
      } else {
        passed = false;
      }
      var t2 = Date.now();
      test.className = passed ? 'pass' : 'fail';
      var timing = 'Of ' + (t2 - t0) + 'ms, parse took '
          + ((t1 - t0) * 100 / (t2 - t0)).toFixed(1) + '%';
      var th = document.createElement('th');
      th.appendChild(document.createTextNode(timing));
      test.appendChild(th);
   } finally {
      groupEnd();
    }
  }
  doTest();
})()</script>

<hr>
<address></address>
<!-- hhmts start --> Last modified: Fri Jan 15 13:11:38 PST 2010 <!-- hhmts end -->
</body> </html>
